import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.net.URI;


public class HdfsTest1 {
    static Configuration conf = new Configuration();
    static FileSystem fs;
    public static void main(String[] args)throws Exception{

        up();
    }
    public static void getList()throws Exception{
        fs = FileSystem.get(conf);
        Path path = new Path("/");
        FileStatus[] list = fs.listStatus(path);
        for(FileStatus f : list){
            System.out.println(f);
        }
    }
    public static void downlo()throws Exception{
        fs = FileSystem.get(conf);
        fs.copyToLocalFile(false,new Path("hadoop-2.6.7.tar.gz"),new Path("e:/"),true);
        fs.close();
    }
    public static void up()throws Exception{
        fs = FileSystem.get(new URI("hdfs://hadoop4:9000"),conf,"hadoop");
        fs.copyFromLocalFile(false,new Path("/aa/ce.txt"),new Path("e:/hadoop"));
        fs.close();
    }
    public static void updata()throws Exception{
        fs = FileSystem.get(new URI("hdfs://hadoop4:9000"),conf,"hadoop");
        Path oldName = new Path("/aa/ce.txt");
        Path newName = new Path("/aa/ce1.txt");
    }
    public static void create()throws Exception{
        fs = FileSystem.get(new URI("hdfs://hadoop4:9000"),conf,"hadoop");
        Path path = new Path("/bb/ce.txt");
        fs.mkdirs(path);
    }
    public static void selects()throws Exception{
        fs = FileSystem.get(new URI("hdfs://hadoop4:9000"),conf,"hadoop");
        String countName = "hello HDFS";
        Path path = new Path("/ce.txt");
        byte[] bytes = countName.getBytes();
        FSDataOutputStream put = fs.append(path);
        put.write(bytes);
    }

}
